package event

import (
	"beergo/app/check/models"
	"beergo/lib/event"
	"beergo/lib/tool"
	"github.com/beego/beego/v2/server/web/context"
)

func init() {
	OnArtCreate()
}

func OnArtCreate() {
	event.ListenJoin("check.OrgArticleNew", func(v interface{}, ctx *context.Context) {
		md,ok:=v.(*models.OrgArticle)
		if ok {
			if md.Org == nil {
				user:=tool.GetUserFromCtx(ctx)
				repOrg:=models.OrgRepository{}
				org:=repOrg.FindOneBy(tool.M{"user":user},nil)
				md.Org = &org
			}
		}
	})
}